<!DOCTYPE html>
<!-- three.js library -->
<script src='vendor/three.js/build/three.js'></script>
<body>
<div style='position: absolute; top: 10px; width:100%; text-align: center; z-index: 1;'>
	<a href="https://github.com/jeromeetienne/AR.js/" target="_blank">AR.js</a> - Experimenting on gravity
	<br/>
	Maybe i can use it to consolidate marker pose ?
</div>

accelerationIncludingGravityX: <span id='accelerationIncludingGravityX'></span><br/>	
accelerationIncludingGravityY: <span id='accelerationIncludingGravityY'></span><br/>	
accelerationIncludingGravityZ: <span id='accelerationIncludingGravityZ'></span><br/>

<hr>

accelerationX: <span id='accelerationX'></span><br/>	
accelerationY: <span id='accelerationY'></span><br/>	
accelerationZ: <span id='accelerationZ'></span><br/>


<hr>

gravityX: <span id='gravityX'></span><br/>	
gravityY: <span id='gravityY'></span><br/>	
gravityZ: <span id='gravityZ'></span><br/>
gravityLength: <span id='gravityLength'></span><br/>

<hr>
	
Absolute: <span id='orientationAbsolute'></span><br/>
Alpha: <span id='orientationAlpha'></span><br/>	
Beta: <span id='orientationBeta'></span><br/>	
Gamma: <span id='orientationGamma'></span><br/>

<script>

// README
// - https://developer.mozilla.org/en-US/docs/Web/API/Detecting_device_orientation
// - https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Orientation_and_motion_data_explained


function onDeviceMotion(event) {
	document.querySelector('#accelerationIncludingGravityX').innerHTML = event.accelerationIncludingGravity.x.toFixed(2)
	document.querySelector('#accelerationIncludingGravityY').innerHTML = event.accelerationIncludingGravity.y.toFixed(2)
	document.querySelector('#accelerationIncludingGravityZ').innerHTML = event.accelerationIncludingGravity.z.toFixed(2)

	document.querySelector('#accelerationX').innerHTML = event.acceleration.x.toFixed(2)
	document.querySelector('#accelerationY').innerHTML = event.acceleration.y.toFixed(2)
	document.querySelector('#accelerationZ').innerHTML = event.acceleration.z.toFixed(2)

	document.querySelector('#gravityX').innerHTML = (event.accelerationIncludingGravity.x - event.acceleration.x).toFixed(2)
	document.querySelector('#gravityY').innerHTML = (event.accelerationIncludingGravity.y - event.acceleration.y).toFixed(2)
	document.querySelector('#gravityZ').innerHTML = (event.accelerationIncludingGravity.z - event.acceleration.z).toFixed(2)
	
	var gravity = new THREE.Vector3()
	gravity.x = event.accelerationIncludingGravity.x - event.acceleration.x
	gravity.y = event.accelerationIncludingGravity.y - event.acceleration.y
	gravity.z = event.accelerationIncludingGravity.z - event.acceleration.z
	document.querySelector('#gravityLength').innerHTML = gravity.length().toFixed(2)
}
window.addEventListener("devicemotion", onDeviceMotion, true);



function onDeviceOrientation(event) {
	document.querySelector('#orientationAbsolute').innerHTML = event.absolute
	document.querySelector('#orientationAlpha').innerHTML = event.alpha.toFixed(2)
	document.querySelector('#orientationBeta').innerHTML = event.beta.toFixed(2)
	document.querySelector('#orientationGamma').innerHTML = event.gamma.toFixed(2)
}

window.addEventListener("deviceorientation", onDeviceOrientation, true);
</script></body>
